//
// Created by Administrator on 2025/8/17.
//

#include "tempsensor.h"
#include "FreeRTOS.h"
#include "task.h"

uint16_t internal_tempsensor_buf[10] = {0};
uint32_t internal_temp_raw = 0;
float internal_temp_celsius = 0.0f;

void internal_temp_process(void *pvParams)
{
    UNUSED(pvParams);
    for (;;)
    {
        // 累加采样值
        internal_temp_raw = 0;
        for (int i = 0; i < 10; i++)
        {
            internal_temp_raw += internal_tempsensor_buf[i];
        }

        // 计算平均 ADC 值
        float adc_avg = (float)internal_temp_raw / 10.0f;

        // 转换为电压 (假设 Vref+ = 3.3V)
        float v_sense = (adc_avg * 3.3f) / 4095.0f;

        // 转换为温度 (典型公式)
        internal_temp_celsius = (v_sense - 0.76f)/0.0025f + 25.0f;
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
}
